package maa.action;

import maa.dao.UserDAO;
import maa.entity.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginPost implements Action {
    @Override
    public ActionResult execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
        UserDAO userDAO = new UserDAO();
        String email = request.getParameter("email");
        String password = request.getParameter("password");
        User user = userDAO.find(email, password);
        ActionResult actionResult = new ActionResult();
        if (user != null) {
            actionResult.setResult("account");
            actionResult.setRedirected(true);
        } else {
            actionResult.setResult("login");
            actionResult.setRedirected(false);
        }
        return actionResult;
    }
}
